import React from 'react';
import { Card, Descriptions } from 'antd';
import { PageContainer } from '@ant-design/pro-layout';
import { detail } from '@/services/Admin';
class Detail extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      detail: {}
    }
  }

  /* 获取详情 */
  getDetail = async () => {
    try {
      const id = this.props.location.query.id;
      const res = await detail(id);
      const date = res.createTime ? res.createTime.split(' ') : [];
      res.date = date[0] || '--';
      this.setState({ detail: res });
    } catch (e) {
      console.log(e)
    }
  }

  componentDidMount() {
    this.getDetail();
  }

  render() {
    const info = this.state.detail;
    console.log(info)
    return (
      <PageContainer>
        <Card
          bodyStyle={{ paddingTop: 24, paddingBottom: 8 }}
          bordered={false}>
          <Descriptions column={4} labelStyle={{ color: '#999' }}>
            <Descriptions.Item label="管理员名称">{info.name}</Descriptions.Item>
            <Descriptions.Item label="管理员角色">{info.role ? info.role.name : '--'}</Descriptions.Item>
            <Descriptions.Item label="创建时间">{info.date}</Descriptions.Item>
            <Descriptions.Item label="管理员性别">{info.sex == 1 ? '男' : (info.sex == 2 ? '女' : '--')}</Descriptions.Item>
            <Descriptions.Item label="管理员地址">{info.address || '--'}</Descriptions.Item>
            <Descriptions.Item label="是否为内置">{info.buildIn ? '是' : '否'}</Descriptions.Item>
            <Descriptions.Item label="管理员账号">{info.loginInput}</Descriptions.Item>
            <Descriptions.Item label="管理员邮箱">{info.email || '--'}</Descriptions.Item>
          </Descriptions>
        </Card>
      </PageContainer>
    );
  }
}

export default Detail;
